package org.javabasics.util;

/**
 * Created by LUOLIANG on 2016/9/21.
 * java中只有值引用
 */
public class ZhiYinYong {
    String str = new String("good");
    char[] ch = {'a', 'b', 'c'};

    public static void changeValue(int num) {
        num = num * 2;
    }

    public static void changeName(Person p) {
        p.name = "luo";
    }

    public void change(String str, char ch[]) {
        str = "test ok";
        ch[0] = 'g';
    }

    public static void main(String[] args) {
        int num = 5;
        System.out.println("引用前：" + num);
        changeValue(num);
        System.out.println("引用后：" + num);

        Person person = new Person();
        System.out.println(person.name);
        changeName(person);
        System.out.println(person.name);

        ZhiYinYong ex = new ZhiYinYong();
        ex.change(ex.str, ex.ch);
        System.out.print(ex.str + " and ");
        System.out.print(ex.ch);
    }
}

class Person {
    public static String name = "luoliang";
}
